[id].vue 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712
  1. <template>
  2. <div id="newsList">
  3. <!-- 页面头部 -->
  4. <HomePageHead></HomePageHead>
  5. <!-- 导航栏 -->
  6. <HomePageNavigation1></HomePageNavigation1>
  7. <!-- 列表页广告一 -->
  8. <HomeTopTen :imgurl="adList[0]" v-if="adList[0]"></HomeTopTen>
  9. <!-- 面包屑导航 -->
  10. <div class="breadcrumb">
  11. <div class="inner">
  12. <span class="location">当前位置:</span>
  13. <el-breadcrumb :separator-icon="ArrowRight">
  14. <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
  15. <el-breadcrumb-item>{{ name }}</el-breadcrumb-item>
  16. </el-breadcrumb>
  17. </div>
  18. </div>
  19. <!-- 资讯列表 -->
  20. <div class="newsList">
  21. <div class="inner">
  22. <div class="innerLeft">
  23. <ul class="list">
  24. <li v-for="(item, index) in newsList" :key="index">
  25. <NuxtLink :to="item.linkurl" target="_blank" v-show="item.islink==1">{{ item.title }}</NuxtLink>
  26. <NuxtLink :to="`/newsDetail/${item.id}`" target="_blank" v-if="item.islink==0">{{ item.title }}</NuxtLink>
  27. </li>
  28. </ul>
  29. <!-- 分页器 -->
  30. <div class="pagination" v-if="total">
  31. <el-pagination size="small" background layout="prev, pager, next" :total="total" class="mt-4"
  32. v-model:page-size="pageSize" prev-text="上一页" next-text="下一页" @change="changePage" />
  33. </div>
  34. </div>
  35. <div class="innerRight">
  36. <DetailHotNews></DetailHotNews>
  37. <DetailHotNews2></DetailHotNews2>
  38. </div>
  39. </div>
  40. </div>
  41. <!-- 列表页广告二 -->
  42. <HomeTopTen :imgurl="adList[1]" v-if="adList[1]"></HomeTopTen>
  43. <!-- 页面底部 -->
  44. <HomeFoot1></HomeFoot1>
  45. </div>
  46. </template>
  47. <script setup>
  48. import { onMounted } from 'vue';
  49. import { ElBreadcrumb, ElBreadcrumbItem, ElPagination } from 'element-plus'
  50. import { ArrowRight } from '@element-plus/icons-vue'
  51. const nuxtApp = useNuxtApp();
  52. const axios = nuxtApp.$axios;
  53. //获得跳转过来的id
  54. const route = useRoute();
  55. const articleId = route.params.id; //获得该页面的id
  56. // const category_id = route.query.category_id; //获得该页面的id
  57. const category_id = route.query.catid; //获得该页面的id
  58. // const name = route.query.name; //获得该页面的id
  59. // console.log(name);
  60. console.log('category_id', category_id);
  61. // 定义响应式数据
  62. const seoData = ref({
  63. title: '三农资讯网',
  64. description: '默认描述',
  65. keywords: '默认关键词',
  66. image: 'https://example.com/default-image.jpg'
  67. });
  68. // 在 onMounted 钩子中获取数据
  69. onMounted(async () => {
  70. try {
  71. const response = await axios.get(`/web/getWebsiteCategoryHead?catid=${articleId}`);
  72. const data = response.data; // 假设接口返回的数据在 data 字段中
  73. console.log(seoData.value.title)
  74. // 更新 seoData
  75. seoData.value = {
  76. title: data.seo_title,
  77. description: data.seo_description,
  78. keywords: data.seo_keywords,
  79. image: data.seo_image
  80. };
  81. console.log(seoData.value.title)
  82. } catch (error) {
  83. console.error('获取 SEO 数据失败:', error);
  84. // 设置默认值
  85. seoData.value = {
  86. title: '三农资讯网',
  87. description: '默认描述',
  88. keywords: '默认关键词',
  89. image: 'https://example.com/default-image.jpg'
  90. };
  91. }
  92. });
  93. // 监听 seoData 的变化,动态设置 SEO 字段
  94. watch(seoData, (newVal) => {
  95. if (newVal.title) { // 确保 title 有值
  96. useSeoMeta({
  97. title: newVal.title, // 使用动态值
  98. description: newVal.description,
  99. ogTitle: newVal.title,
  100. ogDescription: newVal.description,
  101. ogImage: newVal.image,
  102. twitterTitle: newVal.title,
  103. twitterDescription: newVal.description,
  104. twitterImage: newVal.image,
  105. keywords: newVal.keywords
  106. });
  107. }
  108. }, { immediate: true });
  109. //关键词
  110. let keyWord = useState("keyWord", () => "")
  111. let id = useState("id", () => "")
  112. let total = useState("total", () => 0)
  113. let page = useState("page", () => 1)
  114. let pageSize = useState("pageSize", () => 20)
  115. //获得广告
  116. const adList = ref("");
  117. const aa='LIST'
  118. const getadList = async () => {
  119. try {
  120. const response = await axios.get(`/web/getWebsiteAdvertisement?ad_tag=${aa}`);
  121. adList.value = response.data;
  122. } catch (error) {
  123. console.error(error);
  124. }
  125. }
  126. onMounted(() => {
  127. id.value = route.query.id;
  128. console.log('id', id.value);
  129. getadList()
  130. })
  131. // 页码
  132. // //页面组件传递数据的时间驱动函数
  133. // const handleData = (data) => {
  134. // console.log(data.value)
  135. // page.value = data.value
  136. // //在页码发生变化时去请求响应页面的新闻数据
  137. // axios.get(`/web/getWebsiteArticleList?page=${page.value}&pageSize=${10}&catid=${14}&keyword=${keyWord.value}`).then(response => {
  138. // // console.log(response.data.rows);
  139. // newsList.value = response.data.rows;
  140. // }).catch(error => {
  141. // console.error(error);
  142. // })
  143. // }
  144. let changePage = (value) => {
  145. console.log("当前页码", value);
  146. page.value = value
  147. console.log(page.value);
  148. newslists()
  149. }
  150. // 一级导航
  151. const navigation1 = ref("");
  152. const navigateList = async () => {
  153. try {
  154. const response = await axios.get(`/web/getWebsiteModelCategory?placeid=${1}&pid=${0}&num=${24}`);
  155. console.log('一级导航', response.data);
  156. navigation1.value = response.data;
  157. console.log('111111111111111111111111111', navigation1[0]?.value.category_id);
  158. } catch (error) {
  159. console.error(error);
  160. }
  161. }
  162. // 新闻列表
  163. const newsList = useState("newsList", () => '');
  164. const newslists = async () => {
  165. try {
  166. const response = await axios.get(`/web/getWebsiteArticleList?page=${page.value}&pageSize=${pageSize.value}&catid=${articleId}`);
  167. // console.log(response.data.rows);
  168. newsList.value = response.data.rows;
  169. total.value = response.data.count;
  170. } catch (error) {
  171. console.error(error);
  172. }
  173. }
  174. //热点资讯
  175. const hotlistall = useState("hotlistall", () => "");
  176. const hotlist = async () => {
  177. try {
  178. const response = await axios.get(`/web/getWebsiteArticlett?pageSize=${2}&level=${4}&placeid=${1}`);
  179. console.log('热点资讯', response.data);
  180. for (let item of response.data) {
  181. console.log(item);
  182. item.count = 1;
  183. }
  184. hotlistall.value = response.data;
  185. } catch (error) {
  186. console.error(error);
  187. }
  188. }
  189. //资讯推荐1
  190. const news1 = useState("news1", () => "");
  191. const newslist1 = async () => {
  192. try {
  193. const response = await axios.get(`/web/getWebsiteArticlett?pageSize=${1}&level=${5}&placeid=${1}`);
  194. console.log('热点资讯', response.data);
  195. news1.value = response.data;
  196. } catch (error) {
  197. console.error(error);
  198. }
  199. }
  200. const news11 = useState("news11", () => "");
  201. const newslist11 = async () => {
  202. try {
  203. const response = await axios.get(`/web/getWebsiteArticlett?pageSize=${3}&level=${5}&placeid=${1}`);
  204. console.log('热点资讯', response.data);
  205. news11.value = response.data;
  206. } catch (error) {
  207. console.error(error);
  208. }
  209. }
  210. //资讯推荐2
  211. const news2 = useState("news2", () => "");
  212. const newslist2 = async () => {
  213. try {
  214. const response = await axios.get(`/web/getWebsiteArticlett?pageSize=${1}&level=${5}&placeid=${1}`);
  215. console.log('热点资讯', response.data);
  216. news2.value = response.data;
  217. } catch (error) {
  218. console.error(error);
  219. }
  220. }
  221. const news22 = useState("news22", () => "");
  222. const newslist22 = async () => {
  223. try {
  224. const response = await axios.get(`/web/getWebsiteArticlett?pageSize=${3}&level=${5}&placeid=${1}`);
  225. console.log('热点资讯', response.data);
  226. news22.value = response.data;
  227. } catch (error) {
  228. console.error(error);
  229. }
  230. }
  231. const name = useState("name", () => "");
  232. const name1 = async () => {
  233. try {
  234. const response = await axios.get(`/web/getOneWebsiteCategory?catid=${articleId}`);
  235. console.log('name11111111', response.data);
  236. name.value = response.data.name;
  237. navigateList()
  238. } catch (error) {
  239. console.error(error);
  240. }
  241. }
  242. //挂载成功钩子函数
  243. onMounted(() => {
  244. name1()
  245. // 资讯推荐
  246. newslists()
  247. // 热点资讯
  248. hotlist()
  249. // 资讯推荐
  250. newslist1()
  251. newslist2()
  252. // 热点资讯
  253. newslist11()
  254. newslist22()
  255. // navigateList()
  256. })
  257. //路由中间件
  258. definePageMeta({
  259. middleware: 'auth'
  260. })
  261. </script>
  262. <style lang="less" scoped>
  263. #newsList {
  264. width: 100%;
  265. overflow: hidden;
  266. }
  267. //导航条
  268. .breadcrumb {
  269. width: 100%;
  270. height: 22px;
  271. margin-bottom: 30px;
  272. font-family: Microsoft YaHei, Microsoft YaHei;
  273. font-weight: 400;
  274. font-size: 20px;
  275. color: #666666;
  276. line-height: 23px;
  277. text-align: left;
  278. font-style: normal;
  279. text-transform: none;
  280. :deep(.el-breadcrumb) {
  281. display: inline-block;
  282. vertical-align: -4px;
  283. }
  284. :deep(.el-breadcrumb__inner a),
  285. :deep(.el-breadcrumb__inner.is-link) {
  286. color: #666666;
  287. font-weight: 400;
  288. text-decoration: none;
  289. transition: var(--el-transition-color);
  290. }
  291. span {
  292. font-family: Microsoft YaHei, Microsoft YaHei;
  293. font-weight: 400;
  294. font-size: 20px;
  295. color: #666666;
  296. line-height: 23px;
  297. text-align: left;
  298. font-style: normal;
  299. text-transform: none;
  300. }
  301. span:hover {
  302. color: #666666;
  303. }
  304. .location {
  305. margin-right: 20px;
  306. width: 100px;
  307. height: 22px;
  308. font-family: Microsoft YaHei, Microsoft YaHei;
  309. font-weight: 400;
  310. font-size: 20px;
  311. color: #666666;
  312. line-height: 23px;
  313. text-align: left;
  314. font-style: normal;
  315. text-transform: none;
  316. }
  317. }
  318. // 资讯列表
  319. .newsList {
  320. width: 100%;
  321. // height: 675px;
  322. overflow: hidden;
  323. margin-bottom: 70px;
  324. .inner {
  325. width: 1200px;
  326. .innerLeft,
  327. .innerRight {
  328. border-top: 1px solid #139602;
  329. }
  330. .innerLeft {
  331. // height: 675px;
  332. >.list {
  333. // height: 570px;
  334. margin-bottom: 70px;
  335. >li {
  336. width: 790px;
  337. height: 56px;
  338. white-space: nowrap;
  339. overflow: hidden;
  340. text-overflow: ellipsis;
  341. line-height: 56px;
  342. >a {
  343. width: 360px;
  344. height: 26px;
  345. font-family: Microsoft YaHei, Microsoft YaHei;
  346. font-weight: 400;
  347. font-size: 20px;
  348. color: #333333;
  349. line-height: 26px;
  350. text-align: left;
  351. font-style: normal;
  352. text-transform: none;
  353. }
  354. }
  355. >li:hover>a {
  356. color: #139602;
  357. }
  358. >li:nth-child(1)::after,
  359. >li:nth-child(2)::after {
  360. content: "热";
  361. margin-left: 13px;
  362. background: #FF8A37;
  363. color: #fff;
  364. font-size: 14px;
  365. padding: 0px 2px;
  366. }
  367. >li:nth-child(5n) {
  368. // padding-top: 10px;
  369. // padding-bottom: 10px;
  370. border-bottom: 1px solid #D9D9D9;
  371. }
  372. }
  373. >.pagination {
  374. width: 800px;
  375. height: 34px;
  376. margin-left: 141px;
  377. display: flex;
  378. justify-content: center;
  379. margin: 0;
  380. // 鼠标移入后字体颜色
  381. .el-pagination::v-deep :hover {
  382. color: #139609;
  383. }
  384. .el-pagination.is-background::v-deep .btn-next,
  385. .el-pagination.is-background::v-deep .btn-prev {
  386. width: 70px;
  387. height: 34px;
  388. margin: 0px 10px;
  389. border-radius: 4px;
  390. }
  391. .el-pagination.is-background::v-deep .el-pager li {
  392. margin: 0px 10px;
  393. width: 38px;
  394. height: 34px;
  395. border-radius: 4px;
  396. }
  397. .el-pagination.is-background::v-deep .btn-next.is-active,
  398. .el-pagination.is-background::v-deep .btn-prev.is-active,
  399. .el-pagination.is-background::v-deep .el-pager li.is-active {
  400. background-color: #028e21;
  401. color: #fff;
  402. }
  403. }
  404. }
  405. .innerRight {
  406. width: 381px;
  407. // height: 605px;
  408. }
  409. }
  410. }
  411. //资讯推荐
  412. .zixuntuijian {
  413. width: 100%;
  414. height: 290px;
  415. margin-bottom: 70px;
  416. .innerLeft {
  417. // 左侧
  418. .zixunLeft {
  419. margin-right: 30px;
  420. }
  421. .zixunRight,
  422. .zixunLeft {
  423. float: left;
  424. width: 380px;
  425. height: 290px;
  426. // 标题部分
  427. >.title {
  428. width: 380px;
  429. }
  430. >.title>h3 {
  431. height: 36px;
  432. font-family: Source Han Sans, Source Han Sans;
  433. font-weight: bold;
  434. font-size: 24px;
  435. color: #000000;
  436. line-height: 28px;
  437. text-align: left;
  438. font-style: normal;
  439. text-transform: none;
  440. border-bottom: 1px solid #139602;
  441. }
  442. >.title>h3>span {
  443. float: right;
  444. width: 56px;
  445. height: 20px;
  446. line-height: 24px;
  447. font-weight: 400;
  448. font-size: 14px;
  449. color: #999999;
  450. font-style: normal;
  451. text-transform: none;
  452. }
  453. .photo_text {
  454. >li:first-child {
  455. width: 380px;
  456. height: 120px;
  457. margin-top: 20px;
  458. margin-bottom: 15px;
  459. position: relative;
  460. >img {
  461. float: left;
  462. width: 160px;
  463. height: 120px;
  464. }
  465. >div {
  466. float: left;
  467. width: 220px;
  468. height: 120px;
  469. padding-left: 15px;
  470. padding-top: 6px;
  471. box-sizing: border-box;
  472. background-color: #f6f6f6;
  473. >h5 {
  474. width: 200px;
  475. height: 54px;
  476. display: -webkit-box;
  477. -webkit-box-orient: vertical;
  478. -webkit-line-clamp: 2;
  479. overflow: hidden;
  480. text-overflow: ellipsis;
  481. word-break: break-all;
  482. font-family: Source Han Sans, Source Han Sans;
  483. font-weight: 500;
  484. font-size: 18px;
  485. color: #333333;
  486. line-height: 26px;
  487. text-align: left;
  488. font-style: normal;
  489. text-transform: none;
  490. }
  491. >p {
  492. width: 200px;
  493. height: 22px;
  494. line-height: 20px;
  495. position: absolute;
  496. bottom: 5px;
  497. right: 0;
  498. >span {
  499. display: inline-block;
  500. // width: 100px;
  501. height: 18px;
  502. font-family: Source Han Sans, Source Han Sans;
  503. font-weight: 400;
  504. font-size: 12px;
  505. color: #999999;
  506. text-align: left;
  507. line-height: 14px;
  508. font-style: normal;
  509. text-transform: none;
  510. }
  511. >span:last-child {
  512. // width: 90px;
  513. text-align: right;
  514. margin-left: 20px;
  515. }
  516. }
  517. }
  518. }
  519. >li {
  520. width: 380px;
  521. height: 25px;
  522. white-space: nowrap;
  523. overflow: hidden;
  524. text-overflow: ellipsis;
  525. font-family: PingFang SC, PingFang SC;
  526. font-weight: 500;
  527. font-size: 18px;
  528. color: #333333;
  529. line-height: 21px;
  530. text-align: left;
  531. font-style: normal;
  532. text-transform: none;
  533. margin-bottom: 10px;
  534. em {
  535. display: inline-block;
  536. width: 8px;
  537. height: 8px;
  538. border-radius: 8px;
  539. margin-right: 10px;
  540. background-color: #d9d9d9;
  541. }
  542. }
  543. >li:hover {
  544. color: #139602;
  545. }
  546. >li:hover em {
  547. background-color: #139602;
  548. }
  549. }
  550. }
  551. }
  552. .innerRight {
  553. width: 381px;
  554. height: 290px;
  555. background-color: #fbfbfb;
  556. >.title {
  557. width: 380px;
  558. height: 40px;
  559. line-height: 40px;
  560. border-top: 1px solid #139602;
  561. border-bottom: 1px solid #e7e7e7;
  562. >h4 {
  563. font-family: Microsoft YaHei, Microsoft YaHei;
  564. font-weight: 400;
  565. margin-left: 20px;
  566. font-size: 20px;
  567. color: #000000;
  568. text-align: left;
  569. font-style: normal;
  570. text-transform: none;
  571. >span {
  572. float: right;
  573. font-family: Microsoft YaHei, Microsoft YaHei;
  574. font-weight: 400;
  575. font-size: 14px;
  576. margin-right: 10px;
  577. color: #999999;
  578. text-align: left;
  579. font-style: normal;
  580. text-transform: none;
  581. }
  582. }
  583. }
  584. .rightList {
  585. height: 540px;
  586. margin-top: 20px;
  587. >li {
  588. height: 100px;
  589. margin-bottom: 10px;
  590. >img {
  591. width: 150px;
  592. height: 100px;
  593. }
  594. >p {
  595. width: 219px;
  596. height: 100px;
  597. padding-left: 12px;
  598. font-family: PingFang SC, PingFang SC;
  599. font-weight: 400;
  600. font-size: 16px;
  601. color: #333333;
  602. line-height: 22px;
  603. text-align: left;
  604. font-style: normal;
  605. text-transform: none;
  606. }
  607. >p:hover {
  608. box-shadow: 0 0 16px 1px rgba(0, 0, 0, 0.1);
  609. }
  610. }
  611. }
  612. }
  613. }
  614. </style>